//
//  HYCMemoryTool.m
//  FamilyTravel
//
//  Created by dllo on 15/11/10.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "HYCMemoryTool.h"

@implementation HYCMemoryTool
+ (void)isHaveFolder {
    NSString *sanBoxPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
    NSString *memoryFile = [sanBoxPath stringByAppendingPathComponent:@"Memory"];
    NSLog(@"%@", memoryFile);
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:memoryFile]) {
        [manager createDirectoryAtPath:memoryFile withIntermediateDirectories:YES attributes:nil error:nil];
    }
}

+ (void)saveInPlist:(NSDictionary *)dic Plist:(NSString *)plist {
    NSString *sanBoxPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
    NSString *memory = [sanBoxPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Memory/%@", plist]];
    NSLog(@"memory%@", memory);
    [NSKeyedArchiver archiveRootObject:dic toFile:memory];
}

+ (NSDictionary *)backToDictionary:(NSString *)plist {
    NSString *sanBoxPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *memory = [sanBoxPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Memory/%@", plist]];
    //    NSLog(@"%@", memory);
    NSDictionary *dic = [NSKeyedUnarchiver unarchiveObjectWithFile:memory];
    return dic;
}

+ (void)cancelMemoeyFolder {
    NSString *sanBoxPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
    NSString *memoryFile = [sanBoxPath stringByAppendingPathComponent:@"Memory"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL result = [fileManager removeItemAtPath:memoryFile error:nil];
    if (result) {
        NSLog(@"删除缓存成功");
    } else {
        NSLog(@"删除缓存失败");
    }
}




@end
